home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / demostuf / zlogo2.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1994-07-25  |  4.6 KB  |  271 lines

  1. program logo1;
  2. {
  3.   Zoom Logo #2
  4.   - by Bjarke Viksφe
  5.   jun 1994
  6.  
  7.   THIS PROGRAM WAS CODED BY BJARKE VIKS0E.
  8.   YOU ARE FREE TO DO WHATEVER YOU WANT WITH THIS PIECE OF CODE.
  9.   E-MAIL ME AT: dat92230@rix02.lyngbyes.dk IN 1994 FOR CHAT AND CODE.
  10.  
  11.   Doing zooms quite a lot faster than version 1.
  12.   Why? Because of word write to VGA memory!
  13.   Could easily be modifyed to zoom any factor... some other day
  14. }
  15.  
  16. (*{$DEFINE DEBUG}*)
  17.  
  18. uses
  19.     DEMOINIT,ILBM256;
  20.  
  21. type
  22.     SlopeArray = array[0..320] of integer;
  23.  
  24. var
  25.     buffer,tempscreen : pScreen;
  26.     slope : SlopeArray;
  27.     otherslope : SlopeArray;
  28.     y320tabel : array[0..HEIGHT] of word;
  29.  
  30.     xpos,ypos,xsize,ysize : integer;
  31.  
  32. const
  33.     display1 : word = $0000;
  34.     display2 : word = $4000;
  35.     display3 : word = $8000;
  36.  
  37.  
  38. (*------------------------------------------------*)
  39.  
  40. procedure InitDemo;
  41. var
  42.     i : integer;
  43. begin
  44.     Screen_Off;
  45.     FadeCMAP(0);
  46.     ClearWholeScreen;
  47.  
  48.     xsize:=120;
  49.     ysize:=2;
  50.     xpos:=160-(xsize DIV 2);
  51.     ypos:=100-(ysize DIV 2);
  52.  
  53.     for i:=0 to HEIGHT do y320tabel[i]:=i*320;
  54.  
  55.     New(buffer);
  56.     New(tempscreen);
  57.     LoadPix(buffer,'PARASIT1.LBM');
  58.     MakeTweak(buffer,tempscreen);
  59.     SetCMAP;
  60.     Screen_On;
  61. end;
  62.  
  63. procedure UninitDemo;
  64. var
  65.     i : integer;
  66. begin
  67.     Dispose(buffer);
  68.     Dispose(tempscreen);
  69. end;
  70.  
  71.  
  72. (*------------------------------------------------*)
  73.  
  74. procedure SwapDisplay;
  75. var
  76.     temp : word;
  77. begin
  78.     temp:=display3;
  79.     display2:=display1;
  80.     display3:=display2;
  81.     display1:=temp;
  82.     SetAddress(Ptr(SEGA000,display3));
  83. end;
  84.  
  85.  
  86. (*------------------------------------------------*)
  87.  
  88. procedure CalcSlope(x1,x2,ysize : integer); assembler;
  89. { yes, we precalc both horizontal and vertical scaling array.
  90.   Some of u might think this is slow, but who cares!}
  91. asm
  92.     lea    si,slope
  93.     mov    ax,x1
  94.     mov    cx,x2
  95.     mov    dx,ysize
  96.  
  97.     push    ax
  98.     sub    cx,ax
  99.     inc    cx
  100.  
  101.     and    dx,dx
  102.     jz        @zero
  103.  
  104.     cmp    dx,1
  105.     jne    @not1
  106.     dec    cx
  107.     mov    dx,cx
  108.     xor    ax,ax
  109.     jmp    NEAR PTR @one
  110. @not1:
  111.     cmp    dx,2
  112.     jne    @not2
  113.     mov    ax,$7FFF
  114.     imul    cx
  115.     jmp    NEAR PTR @one
  116. @not2:
  117.  
  118.     mov    dx,$0001
  119.     mov    ax,$0000
  120.     idiv    ysize
  121.     imul    cx
  122. @one:
  123.     pop    cx
  124.     xor    bx,bx
  125.  
  126.     inc    ysize
  127.     mov    di,ysize
  128. @loop:
  129.     mov    [si],cx
  130.     add    si,2
  131.     add    bx,ax
  132.     adc    cx,dx
  133.     dec    di
  134.     jnz    @loop
  135. @zero:
  136. end;
  137.  
  138.  
  139. (*------------------------------------------------*)
  140.  
  141. procedure ZoomLine(xpos,ysize,dst_offset : word); assembler;
  142. asm
  143.     mov    es,SEGA000
  144.     mov    di,dst_offset
  145.     add    di,display1
  146.     mov    ax,WORD PTR buffer+2
  147.     {mov fs,ax} DB $8E,$E0
  148.     mov    dx,xpos
  149.     add    dx,WORD PTR buffer
  150.     lea    si,slope
  151.     mov    cx,ysize
  152.     cld
  153. @yloop:
  154.     lodsw
  155.     add    ax,dx
  156.     mov    bx,ax
  157.     DB FS; mov    al,[bx]
  158.     mov    [es:di],al
  159.     add    di,WIDTH
  160.     dec    cl
  161.     jnz    @yloop
  162. end;
  163.  
  164. procedure Zoom2Lines(xpos1,xpos2,ysize,dst_offset : word); assembler;
  165. {this same is the above - only it takes a word instead of a single byte
  166.  Speeds up things a bit on slow vga-cards [like mine :-( ]}
  167. asm
  168.     push    bp {zooms two pixel in tweak-mode - so eg pixel 0 and 3 ...}
  169.     mov    es,SEGA000
  170.     mov    di,dst_offset
  171.     add    di,display1
  172.     mov    ax,WORD PTR buffer+2
  173.     {mov fs,ax} DB $8E,$E0
  174.     mov    dx,xpos1
  175.     add    dx,WORD PTR buffer
  176.  
  177.     mov    cx,ysize
  178.  
  179.     mov    ax,xpos2
  180.     sub    ax,xpos1
  181.     mov    bp,ax
  182.  
  183.     lea    si,slope
  184.     cld
  185. @yloop:
  186.     lodsw
  187.     add    ax,dx
  188.     mov    bx,ax
  189.     DB FS; mov    al,[bx]
  190.     add    bx,bp
  191.     DB FS; mov    ah,[bx]
  192.     mov    [es:di],ax
  193.     add    di,WIDTH
  194.     dec    cl
  195.     jnz    @yloop
  196.     pop    bp
  197. end;
  198.  
  199.  
  200. (*------------------------------------------------*)
  201.  
  202.  
  203. procedure RunOnce;
  204. var
  205.     i,j : integer;
  206.     dst_offset : word;
  207. begin
  208.     SwapDisplay;
  209. {$IFNDEF DEBUG}
  210.     while retraces=0 do ;
  211.     retraces:=0;
  212. {$ELSE}
  213.     VBLANK;
  214.     SetRGB(0,30,0,0);
  215. {$ENDIF}
  216.  
  217.     CalcSlope(0,319,xsize);
  218.     otherslope:=slope;
  219.     CalcSlope(0,199,ysize);
  220.     for i:=0 to ysize do slope[i]:=y320tabel[slope[i]];
  221.  
  222.     dst_offset:=longmul(ypos,WIDTH)+(xpos shr 2);
  223.     j:=0;
  224.     i:=xpos;
  225.  
  226.     {zoom first byte if we are on an odd address}
  227.     while (i < xpos+xsize) AND odd(dst_offset) do begin
  228.         SetBitplanes(1 shl (i AND 3));
  229.         ZoomLine(otherslope[j],ysize,dst_offset);
  230.         inc(j);
  231.         inc(i); if ((i AND 3)=0) then inc(dst_offset);
  232.     end;
  233.  
  234.     {zoom rest of picture in words}
  235.     while (i < xpos+xsize) do begin
  236.         SetBitplanes(1 shl (i AND 3));
  237.         Zoom2Lines(otherslope[j],otherslope[j+4],ysize,dst_offset);
  238.         inc(j);
  239.         inc(i);
  240.         if ((i AND 3)=0) then begin
  241.             inc(i,4);
  242.             inc(j,4);
  243.             inc(dst_offset,2);
  244.         end;
  245.     end;
  246.  
  247.     {NOTICE: last pixel row (byte) may be skipped in some zooms!}
  248.  
  249.     if (xpos>0) AND (ypos>0) then begin
  250.         {get new zoom-values}
  251.         dec(xpos);
  252.         dec(ypos);
  253.         inc(xsize,2);
  254.         inc(ysize,2);
  255.     end;
  256. {$IFDEF DEBUG}
  257.     SetRGB(0,0,0,0);
  258. {$ENDIF}
  259. end;
  260.  
  261.  
  262. begin
  263.     OpenScreen;
  264.     InitDemo;
  265.     SetAllInterrupts;
  266.     repeat RunOnce until Key='e';
  267.     RestoreAllInterrupts;
  268.     UninitDemo;
  269.     CloseScreen;
  270. end.
  271.